package com.sys.goods.service.impl;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sys.common.pojo.ApiResponse;
import com.sys.common.pojo.ApiResponseEnum;
import com.sys.common.pojo.JSONEnum;
import com.sys.common.util.ConstatFinalUtil;
import com.sys.common.util.DateFormatUtil;
import com.sys.common.util.FileUtil;
import com.sys.common.util.PageInfoUtil;
import com.sys.goods.dao.IAAddressDao;
import com.sys.goods.dao.IABlindboxDao;
import com.sys.goods.dao.IAGoodsDao;
import com.sys.goods.pojo.AAddress;
import com.sys.goods.pojo.AAddressEnum;
import com.sys.goods.pojo.ABlindbox;
import com.sys.goods.pojo.ABlindboxEnum;
import com.sys.goods.pojo.AGoods;
import com.sys.goods.pojo.AGoodsEnum;
import com.sys.goods.service.IGoodsDbService;

@Service("goodsDbService")
public class GoodsDbServiceImpl implements IGoodsDbService
{
	@Autowired
	private IAGoodsDao goodsDao;
	@Autowired
	private FileUtil fileUtil;
	@Autowired
	private DateFormatUtil dateFormatUtil;
	@Autowired
	private IABlindboxDao blindboxDao;
	@Autowired
	private IAAddressDao addressDao;

	@Override
	public ApiResponse<Object> saveOneAGoodsService(AGoods goods)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		
		goods.setCreateTime(new Date());
		goods.setUpdateTime(new Date());
		goods.setPubTime(new Date());
		goods.setShelfTime(new Date());
		
		goods.setStatus(AGoodsEnum.STATUS_ENABLE.getStatus());
		
		/* 调用dao保存数据库 */
		int res = goodsDao.save(goods);

		if (res > 0) {
			
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), goods.getGoodsId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), goods);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneAGoodsService(AGoods goods)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		goods.setUpdateTime(new Date());
		int res = this.goodsDao.update(goods);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), goods.getGoodsId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), goods);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneAGoodsService(AGoods goods, Map<String, Object> paramsMap)
	{
		/* 先更新用户的信息 */
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			String fileName = paramsMap.get("fileName") + "";
			InputStream is = (InputStream) paramsMap.get("is") ;
			
			/* 上传文件的相对路径   /uploadfile/  */
			String uploadFile = ConstatFinalUtil.CONFIG_JSON.getString("website.uploadFile");
			/* 存储的是网址的绝对路径 */ 
			String souPath = goods.getGoodsPicture();
			/* 真实路径  D:/项目空间/usersCenter/usersCenter-web/usersCenter-web-head/src/main/webapp/ */
			String truePath = ConstatFinalUtil.CONFIG_JSON.getString("website.truePath");
			/* 网站的相对路径 */
			String tarRelaPath = uploadFile + "goods/" + this.dateFormatUtil.dateStr(new Date()) + "/" + UUID.randomUUID().toString() + 
					fileName.substring(fileName.lastIndexOf("."), fileName.length());
			File tarTrueFile = new File(truePath + tarRelaPath.substring(1));
			
			/* 创建父目录 */
			if(!tarTrueFile.getParentFile().exists())
			{
				tarTrueFile.getParentFile().mkdirs();
			}
			/* 设置路径 */
			goods.setGoodsPicture(tarRelaPath);
			FileOutputStream fos = new FileOutputStream(tarTrueFile);
			/* 复制文件 */
			boolean flag = this.fileUtil.copyFile(is, fos);
			if(flag)
			{
				if(souPath != null && !"".equalsIgnoreCase(souPath))
				{
					souPath=truePath+souPath;
					/* 相对路径 */
					File souFile = new File(souPath);
					if(!souFile.delete())
					{
						ConstatFinalUtil.SYS_LOGGER.error("删除原始文件失败:原始文件路径:{}",souFile.getAbsolutePath());
					}
				}
			}
			/* 更新用户信息 */
			apiResponse = this.updateOneAGoodsService(goods);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("上传头像失败了,id:{}",goods.getGoodsId() , e);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneAGoodsService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.goodsDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AGoods> findOneAGoodsService(Map<String, Object> condMap)
	{
		ApiResponse<AGoods> apiResponse = new ApiResponse<AGoods>();

		Map<String, AGoods> data = new HashMap<String, AGoods>();
		AGoods goods = this.goodsDao.findOne(condMap);
		
		if("true".equalsIgnoreCase(condMap.get("extend") + ""))
		{
			/* 查询关联关系 */
			Map<String, Object> extMap = new HashMap<String, Object>();
			extMap.clear();
			extMap.put("id", goods.getBlindBoxId());
//			ApiResponse<ABlindbox> cateApiResponse = this.findOneABlindboxService(extMap);
//			ABlindbox blindbox = cateApiResponse.getDataOneJava();
//			goods.setBlindbox(blindbox);
			
		}
		
		data.put(ApiResponseEnum.NAME_ONE.getName(), goods);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(goods);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AGoods> findCondListAGoodsService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<AGoods> apiResponse = new ApiResponse<AGoods>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<AGoods> demoGoodsList = Collections.EMPTY_LIST;
		
		if(condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + "")) {
			condMap.put("keyword", "%" + condMap.get("keyword") + "%");
		}

		Map<String, List<AGoods>> dataList = new HashMap<String, List<AGoods>>();
		if(pageInfoUtil != null){
			Page<Object> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			demoGoodsList = this.goodsDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Long.valueOf(page.getTotal()).intValue());
		}else {
			demoGoodsList = this.goodsDao.findCondList(condMap);
		}
		
		if("true".equalsIgnoreCase(condMap.get("extend") + ""))
		{
			/* 查询关联关系 */
			Map<String, Object> extMap = new HashMap<String, Object>();
			
			for (Iterator iterator = demoGoodsList.iterator(); iterator.hasNext();)
			{
				AGoods goods = (AGoods) iterator.next();
				
				extMap.clear();
//				extMap.put("id", goods.getBlindBoxId());
//				ApiResponse<ABlindbox> cateApiResponse = this.findOneABlindboxService(extMap);
//				ABlindbox blindbox = cateApiResponse.getDataOneJava();
//				goods.setBlindbox(blindbox);
				
			}
		}
		
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoGoodsList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoGoodsList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}
	/* =====================ABlindbox======================= */
	@Override
	public ApiResponse<Object> saveOneABlindboxService(ABlindbox blindbox)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();

		blindbox.setCreateTime(new Date());
		blindbox.setUpdateTime(new Date());
		blindbox.setPubTime(new Date());
		blindbox.setStatus(ABlindboxEnum.STATUS_ENABLE.getStatus());
		
		int res = this.blindboxDao.save(blindbox);
		if (res > 0)
		{
			/* 批量保存商品 */
			for(int i = 0 ; i < blindbox.getBlindBoxNumber() ; i ++) {
				AGoods goods = new AGoods();
				goods.setBlindBoxId(res);
				goods.setGoodsName(blindbox.getBlindBoxIntroduce() + "_商品_" + i );
				goods.setGoodsPrices(blindbox.getBlindBoxPrices());
				goods.setGoodsIntroduce(blindbox.getBlindBoxIntroduce());
				goods.setGoodsPicture(blindbox.getBlindBoxPicture());
				goods.setGoodsQuantity(100);
				goods.setCommodityBrand("品牌_" + i);
				goods.setShelfTime(new Date());
				this.saveOneAGoodsService(goods);
			}
			
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), blindbox.getBlindBoxId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), blindbox);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneABlindboxService(ABlindbox blindbox)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		blindbox.setUpdateTime(new Date());
		int res = this.blindboxDao.update(blindbox);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), blindbox.getBlindBoxId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), blindbox);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneABlindboxService(ABlindbox blindbox, Map<String, Object> paramsMap)
	{
		/* 先更新用户的信息 */
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		try
		{
			String fileName = paramsMap.get("fileName") + "";
			InputStream is = (InputStream) paramsMap.get("is") ;
			
			/* 上传文件的相对路径   /uploadfile/  */
			String uploadFile = ConstatFinalUtil.CONFIG_JSON.getString("website.uploadFile");
			/* 存储的是网址的绝对路径 */ 
			String souPath = blindbox.getBlindBoxPicture();
			/* 真实路径  D:/项目空间/usersCenter/usersCenter-web/usersCenter-web-head/src/main/webapp/ */
			String truePath = ConstatFinalUtil.CONFIG_JSON.getString("website.truePath");
			/* 网站的相对路径 */
			String tarRelaPath = uploadFile + "blindbox/" + this.dateFormatUtil.dateStr(new Date()) + "/" + UUID.randomUUID().toString() + 
					fileName.substring(fileName.lastIndexOf("."), fileName.length());
			File tarTrueFile = new File(truePath + tarRelaPath.substring(1));
			
			/* 创建父目录 */
			if(!tarTrueFile.getParentFile().exists())
			{
				tarTrueFile.getParentFile().mkdirs();
			}
			/* 设置路径 */
			blindbox.setBlindBoxPicture(tarRelaPath);
			FileOutputStream fos = new FileOutputStream(tarTrueFile);
			/* 复制文件 */
			boolean flag = this.fileUtil.copyFile(is, fos);
			if(flag)
			{
				if(souPath != null && !"".equalsIgnoreCase(souPath))
				{
					souPath=truePath+souPath;
					/* 相对路径 */
					File souFile = new File(souPath);
					if(!souFile.delete())
					{
						ConstatFinalUtil.SYS_LOGGER.error("删除原始文件失败:原始文件路径:{}",souFile.getAbsolutePath());
					}
				}
			}
			/* 更新用户信息 */
			apiResponse = this.updateOneABlindboxService(blindbox);
		} catch (Exception e)
		{
			ConstatFinalUtil.SYS_LOGGER.error("上传头像失败了,id:{}",blindbox.getBlindBoxId() , e);
		}
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneABlindboxService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.blindboxDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<ABlindbox> findOneABlindboxService(Map<String, Object> condMap)
	{
		ApiResponse<ABlindbox> apiResponse = new ApiResponse<ABlindbox>();

		Map<String, ABlindbox> data = new HashMap<String, ABlindbox>();
		ABlindbox blindbox = this.blindboxDao.findOne(condMap);
	
		data.put(ApiResponseEnum.NAME_ONE.getName(), blindbox);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(blindbox);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	
	}

	@Override
	public ApiResponse<ABlindbox> findCondListABlindboxService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<ABlindbox> apiResponse = new ApiResponse<ABlindbox>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<ABlindbox> demoBlindboxList = Collections.EMPTY_LIST;
		
		if(condMap.get("keyword") != null && !"".equalsIgnoreCase(condMap.get("keyword") + "")) {
			condMap.put("keyword", "%" + condMap.get("keyword") + "%");
		}

		Map<String, List<ABlindbox>> dataList = new HashMap<String, List<ABlindbox>>();
		if(pageInfoUtil != null){
			Page<Object> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			demoBlindboxList = this.blindboxDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Long.valueOf(page.getTotal()).intValue());
		}else {
			demoBlindboxList = this.blindboxDao.findCondList(condMap);
		}
		
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoBlindboxList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoBlindboxList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	/*==============================Address===================================*/
	@Override
	public ApiResponse<Object> saveOneAAddressService(AAddress address)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		
		/* 如果当前的地址类型是默认的
		 * 先全部把地址类型修改为默认的,
		 * 然后再添加
		 *  */
		if(address.getIsTheDefaultAddress() == AAddressEnum.DEFAULT_YES.getStatus()) {
			/* 全部变成非默认的 */
			Map<String,Object> condMap = new HashMap<String, Object>();
			condMap.put("userId", address.getUserId());
			condMap.put("isTheDefaultAddress", AAddressEnum.DEFAULT_NO.getStatus());
			this.updateBatchAAddressService(condMap);
		}

		address.setCreateTime(new Date());
		address.setUpdateTime(new Date());
		address.setPubTime(new Date());
		address.setStatus(AAddressEnum.STATUS_ENABLE.getStatus());
		
		int res = this.addressDao.save(address);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), address.getAddressId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), address);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateOneAAddressService(AAddress address)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		
		/* 如果当前的地址类型是默认的
		 * 先全部把地址类型修改为默认的,
		 * 然后再添加
		 *  */
		if(address.getIsTheDefaultAddress() == AAddressEnum.DEFAULT_YES.getStatus()) {
			/* 全部变成非默认的 */
			Map<String,Object> condMap = new HashMap<String, Object>();
			condMap.put("userId", address.getUserId());
			condMap.put("isTheDefaultAddress", AAddressEnum.DEFAULT_NO.getStatus() + "");
			this.updateBatchAAddressService(condMap);
		}
		
		address.setUpdateTime(new Date());
		int res = this.addressDao.update(address);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			dataMap.put(JSONEnum.ID.getName(), address.getAddressId());
			dataMap.put(ApiResponseEnum.NAME_ONE.getName(), address);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> deleteOneAAddressService(Map<String, Object> condMap)
	{
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.addressDao.delete(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AAddress> findCondListAAddressService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		ApiResponse<AAddress> apiResponse = new ApiResponse<AAddress>();
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		List<AAddress> demoCateList = Collections.EMPTY_LIST;

		Map<String, List<AAddress>> dataList = new HashMap<String, List<AAddress>>();
		if(pageInfoUtil != null){
			Page<Object> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			demoCateList = this.addressDao.findCondList(condMap);
			pageInfoUtil.setTotalRecord(Long.valueOf(page.getTotal()).intValue());
		}else {
			demoCateList = this.addressDao.findCondList(condMap);
		}
		/* 将结果放到JSON中 */
		dataList.put(ApiResponseEnum.NAME_LIST.getName(), demoCateList);

		apiResponse.setPageInfoUtil(pageInfoUtil);
		apiResponse.setDataListJava(demoCateList);
		apiResponse.setDataList(dataList);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<AAddress> findOneAAddressService(Map<String, Object> condMap)
	{
		ApiResponse<AAddress> apiResponse = new ApiResponse<AAddress>();

		Map<String, AAddress> data = new HashMap<String, AAddress>();
		AAddress address = this.addressDao.findOne(condMap);
		data.put(ApiResponseEnum.NAME_ONE.getName(), address);
		apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		/* 将结果放到JSON中 */
		apiResponse.setDataOne(data);
		apiResponse.setDataOneJava(address);
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

	@Override
	public ApiResponse<Object> updateBatchAAddressService(Map<String, Object> condMap) {
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		int res = this.addressDao.updateBatch(condMap);
		if (res > 0)
		{
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put(JSONEnum.EFFECT.getName(), res);
			apiResponse.setDataOne(dataMap);

			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
		} else
		{
			apiResponse.setCode(ApiResponseEnum.STATUS_FAILED.getStatus());
		}
		apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
		return apiResponse;
	}

}
